package com.qf.fcy.youshare.model;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created with IntelliJ IDEA.
 * User: Alex[FR]
 * Date: 2015/2/5
 * Email: alex_fcy@163.com
 */

/**
 * 如果接口明确标注哪些字段必选，那么就使用getXXX这种方法，如果明确说明是可选的，那么就可以
 * 使用optXXX方法来获取。（有些服务器接口文档可能会写错，需要充分测试）
 */
public class Product {

    private String appGname;// "智能咖啡杯",
    private String goodsName;//"goods_name" "不锈钢智能感温咖啡杯",
    private String type;//"type" "0",
    private String url;//"url" "goods.php?id=134",
    private String goodsImg;//"goods_img" "images_no_picture.gif",
    private String promotePrice;//"promote_price" "",
    private String goodsBrief;//"goods_brief" "外观与功能都无可挑剔",
    private String shopPrice;//"shop_price" "￥98元",
    private String marketPrice;//"market_price" "￥118元",
    private String name;//"name" "不锈钢智能感温咖啡杯",
    private String goodsId;//"goods_id" "134",
    private String goodsStyleName;//"goods_style_name" "不锈钢智能感温咖啡杯",
    private String goodsThumb;//"goods_thumb" "images/thumb_img_thumb_G_1414811942965.png",
    private String addTime;//"add_time" "2014-10-17"


    // TODO 解析JSON的方法，必须在这个方法内部
    public void parseJSON(JSONObject json) {
        if (json != null) {
            // 解析JSON的时候，必须注意的是，那些成员、字段是可选的，或者是服务器
            // 可能返回为null的, 采用optXXX

            try {
                // 必须存在的字段 优先解析，这样保证数据的有效性
                type = json.getString("type");
                goodsImg = json.getString("goods_img");
                shopPrice = json.getString("shop_price");
                goodsId = json.getString("goods_id");
                goodsThumb = json.getString("goods_thumb");

                appGname = json.optString("app_gname");
                goodsName = json.optString("goods_name");
                url = json.optString("url");
                promotePrice = json.optString("promote_price");
                goodsBrief = json.optString("goods_brief");
                marketPrice = json.optString("market_price");
                name = json.optString("name");
                goodsStyleName = json.optString("goods_style_name");
                addTime = json.optString("add_time");

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public String getAppGname() {
        return appGname;
    }

    public void setAppGname(String appGname) {
        this.appGname = appGname;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getGoodsImg() {
        return goodsImg;
    }

    public void setGoodsImg(String goodsImg) {
        this.goodsImg = goodsImg;
    }

    public String getPromotePrice() {
        return promotePrice;
    }

    public void setPromotePrice(String promotePrice) {
        this.promotePrice = promotePrice;
    }

    public String getGoodsBrief() {
        return goodsBrief;
    }

    public void setGoodsBrief(String goodsBrief) {
        this.goodsBrief = goodsBrief;
    }

    public String getShopPrice() {
        return shopPrice;
    }

    public void setShopPrice(String shopPrice) {
        this.shopPrice = shopPrice;
    }

    public String getMarketPrice() {
        return marketPrice;
    }

    public void setMarketPrice(String marketPrice) {
        this.marketPrice = marketPrice;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public String getGoodsStyleName() {
        return goodsStyleName;
    }

    public void setGoodsStyleName(String goodsStyleName) {
        this.goodsStyleName = goodsStyleName;
    }

    public String getGoodsThumb() {
        return goodsThumb;
    }

    public void setGoodsThumb(String goodsThumb) {
        this.goodsThumb = goodsThumb;
    }

    public String getAddTime() {
        return addTime;
    }

    public void setAddTime(String addTime) {
        this.addTime = addTime;
    }
}
